//
//  BankCardListViewController.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/5.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "BankCardListViewController.h"
#import "AddBankCardViewController.h"

@interface BankCardListViewController ()
@property (nonatomic, strong) BankCardListViewModel *viewModel;

@end

@implementation BankCardListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的银行卡";
    [self addNavigationItemWithTitles:@[@"编辑"] isLeft:NO target:self action:@selector(rightAction:) tags:@[@232] theButTitColor:kColor_Rule_Yellow titFont:SYSTEMFONT(15)];
    self.viewModel = [[BankCardListViewModel alloc] initWithViewToViewModel:self.groupedTableView theSuperView:self.view];
    self.viewModel.type = self.type;
    self.viewModel.refreshType = AddOrEditType_Defat;
    kWeakSelf(self);
    self.viewModel.BlockChooseBank = ^(NSDictionary * _Nullable dic) {
        [weakself chooseBank:dic];
    };
    self.viewModel.BlockNoData = ^{
        [weakself noDataNavi];
    };
    self.viewModel.BlockAddCard = ^(GLGWButton * _Nullable btn) {
        [weakself addBankCard:btn];
    };
}

- (void)addBankCard:(GLGWButton *)sender
{
    AddBankCardViewController *vc = [AddBankCardViewController new];
    self.navigationItem.rightBarButtonItem.customView.hidden = NO;
    kWeakSelf(self);
    vc.BlockKeepCard = ^(BankCardDetailModel * _Nullable deModel) {
        if (weakself.viewModel.model.data.count <= 0) {
            weakself.viewModel.model.data = [NSMutableArray array];
        }
        [weakself.viewModel.model.data insertObject:deModel atIndex:0];
        weakself.viewModel.refreshType = AddOrEditType_Add;
    };
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)noDataNavi
{
    self.navigationItem.rightBarButtonItem.customView.hidden = YES;
}

- (void)chooseBank:(NSDictionary *)dic
{
    if (self.BlockChooseBank) {
        self.BlockChooseBank(dic);
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)rightAction:(UIButton *)sender
{
    [self.viewModel setEdit:sender];
}

- (void)noData{}

@end
